# Maintainer: James Ross-Gowan <rossymiles@gmail.com>

pkgbase=protobuf
pkgname=('protobuf' 'protobuf-devel')
pkgver=3.6.1
pkgrel=1
pkgdesc="Protocol Buffers - Google's data interchange format"
arch=('i686' 'x86_64')
url='https://developers.google.com/protocol-buffers/'
groups=('libraries')
license=('BSD')
depends=('gcc-libs' 'zlib')
makedepends=('zlib-devel')
source=(protobuf-${pkgver}.tar.gz::https://github.com/google/protobuf/archive/v${pkgver}.tar.gz
        01-msysize.patch)
sha256sums=('3d4e589d81b2006ca603c1ab712c9715a76227293032d05b26fca603f90b3f5b'
            '9cfdfc73ccfd2234733cfef31c1fa88b78514f1368341fecdfd0a779c4da8893')

prepare() {
  cd "${srcdir}/protobuf-${pkgver}"
  patch -p1 -i "${srcdir}/01-msysize.patch"
  ./autogen.sh
}

build() {
  cd "${srcdir}/protobuf-${pkgver}"

  ./configure \
    --host=${CHOST} \
    --prefix=/usr
  make
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd "${srcdir}/protobuf-${pkgver}"
  make check
}

package_protobuf() {
  mkdir -p "${pkgdir}/usr/bin"
  cp -f "${srcdir}/dest/usr/bin/"*.dll "${pkgdir}/usr/bin/"
  install -Dm644 "${srcdir}/protobuf-${pkgver}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

package_protobuf-devel() {
  pkgdesc="Protobuf headers and libraries"
  groups=('development')
  depends=("protobuf=${pkgver}")

  mkdir -p "${pkgdir}/usr/bin"
  cp -f "${srcdir}/dest/usr/bin/"*.exe "${pkgdir}/usr/bin/"
  cp -rf "${srcdir}/dest/usr/include" "${pkgdir}/usr/"
  cp -rf "${srcdir}/dest/usr/lib" "${pkgdir}/usr/"
}
